<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .one{
            width: 100px;
            height: 100px;
            background-color: red;
            color: #fff;
        }
        .two{
            width: 100px;
            height: 100px;
            background-color: blue;
            color: #fff;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">

    /* 
        状态提升：
        将子组件的数据传递给父组件，父组件再将其数据传递给另一个子组件
    */
    class App extends React.Component {
        state = {
            towNum:""
        }
        render() {
            return (
                <div>
                    <h1>父组件</h1>
                    <One num={this.state.towNum}/>
                    <Two getNum={(num)=>{
                        this.setState({towNum:num})
                    }}/>
                </div>
            )
        }
    }
    class One extends React.Component {
        state = {

        }
        render() {
            return (
                <div className='one'>
                        one子组件---{this.props.num}
                </div>
            )
        }
    }
    class Two extends React.Component {
        state = {
            num:1000
        }
        render() {
            return (
                <div className='two'>
                    tow子组件---{this.state.num}
                    <button onClick={()=>{
                        this.props.getNum(this.state.num)
                    }}>向另一个子组件传递数据</button>
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById("root"))
</script>

</html>